package com.qiyun.dinghuohui.common;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.v4.app.Fragment;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestListener;
import com.qiyun.dinghuohui.utils.LogDebug;

/**
 * Created by xlm on 2018/5/29
 */

public class ImageUtils {
    public static final String  imagUrl = "https://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike272%2C5%" +
            "2C5%2C272%2C90/sign=46ef876d76d98d1062d904634056d36b/8d5494eef01f3a2945c7c45f9325bc315c607c17.jpg";
    public static final String TAG_GLIDE = "pic";

    public static void clearDiskCache(Activity context) {
        Glide.get(context).clearDiskCache();
    }

    public static void clearDiskCache(Context context) {
        Glide.get(context).clearDiskCache();
    }

    public static void clearMemoryCache(Activity context) {
        Glide.get(context).clearMemory();
    }

    public static void clearMemoryCache(Context context) {
        Glide.get(context).clearMemory();
    }

    public static void showImage(Activity activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Fragment activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Context activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Activity activity, ImageView imageView, int w, int h, @DrawableRes int resId) {
        Glide.with(activity).load(resId).override(w, h).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Activity activity, ImageView imageView, String url) {
//        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Fragment activity, ImageView imageView, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Context activity, ImageView imageView, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Activity activity, ImageView imageView, int w, int h, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).override(w, h).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Fragment activity, ImageView imageView, int w, int h, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).override(w, h).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImage(Context activity, ImageView imageView, int w, int h, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).override(w, h).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void preLoad(Activity activity, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).preload();
    }

    public static void preLoad(Fragment activity, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).preload();
    }

    public static void preLoad(Context activity, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).preload();
    }

    public static void showImageNoGif(Activity activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImageNoGif(Fragment activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImageNoGif(Context activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImageNoGif(Activity activity, ImageView imageView, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImageNoGif(Fragment activity, ImageView imageView, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImageNoGif(Context activity, ImageView imageView, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().into(imageView);
    }

    public static void showImageWithListener(Activity activity, ImageView imageView, @DrawableRes int resId, RequestListener listener) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().listener(listener).into(imageView);
    }

    public static void showImageWithListener(Fragment activity, ImageView imageView, @DrawableRes int resId, RequestListener listener) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().listener(listener).into(imageView);
    }

    public static void showImageWithListener(Context activity, ImageView imageView, @DrawableRes int resId, RequestListener listener) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().listener(listener).into(imageView);
    }

    public static void showImageWithListener(Activity activity, ImageView imageView, String url, RequestListener listener) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().listener(listener).into(imageView);
    }

    public static void showImageWithListener(Fragment activity, ImageView imageView, String url, RequestListener listener) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().listener(listener).into(imageView);
    }

    public static void showImageWithListener(Context activity, ImageView imageView, String url, RequestListener listener) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate().listener(listener).into(imageView);
    }

    public static void showImageCacheResult(Activity activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.RESULT).dontAnimate().into(imageView);
    }

    public static void showImageCacheResult(Fragment activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.RESULT).dontAnimate().into(imageView);
    }

    public static void showImageCacheResult(Context activity, ImageView imageView, @DrawableRes int resId) {
        Glide.with(activity).load(resId).diskCacheStrategy(DiskCacheStrategy.RESULT).dontAnimate().into(imageView);
    }

    public static void showImageCacheResult(Activity activity, ImageView imageView, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.RESULT).dontAnimate().into(imageView);
    }

    public static void showImageCacheResult(Fragment activity, ImageView imageView, String url) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.RESULT).dontAnimate().into(imageView);
    }

    public static void showImageCacheResult(Context activity, ImageView imageView, String url, @DrawableRes int resId) {
        LogDebug.d(TAG_GLIDE, url);
        Glide.with(activity).load(url).diskCacheStrategy(DiskCacheStrategy.RESULT).dontAnimate().into(imageView);
    }
}
